package com.awspaas.user.apps.shhtaerospaceindustrial.event;

import java.util.List;
import java.util.Map;
import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.InterruptListenerInterface;
import com.actionsoft.bpms.commons.database.ColumnMapRowMapper;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.exception.BPMNError;
import com.awspaas.user.apps.shhtaerospaceindustrial.util.CoreUtil;

/**
 * 
 * @Description:表单办理前校验，检查被访单位的接待人是否存在
 * @author: dingyi
 * @date: 2021年6月28日 上午9:42:30
 */
public class checkVisitorTaegetValidateEvent149 implements InterruptListenerInterface {

	@Override
	public String getDescription() {

		return "表单办理前校验  ";
	}

	@Override
	public String getProvider() {

		return "dingyi";
	}

	@Override
	public String getVersion() {

		return "1.0";
	}

	@Override
	public boolean execute(ProcessExecutionContext processExecutionContext) throws Exception {
		// 获取流程实例ID
		String processInstId = processExecutionContext.getProcessInstance().getId();
		// 根据流程实例ID获取任务表内数据
		List<Map<String, Object>> visitmain = DBSql.query("SELECT * FROM BO_EU_VIT_MANGE_TOOFN WHERE BINDID = ? ",
				new ColumnMapRowMapper(), new Object[] { processInstId });

//		for (Map<String, Object> map : visitmain) {
			Map<String, Object> employee = visitmain.get(0);
			String TARGETMAN = CoreUtil.objToStr(employee.get("TARGETMAN"));// 被访客姓名
			String TARGETDEPT = CoreUtil.objToStr(employee.get("TARGETDEPT"));// 被访部门
			String TARGETUNIT = CoreUtil.objToStr(employee.get("TARGETUNIT"));// 被访单位
			String TARGETMANUID = CoreUtil.objToStr(employee.get("TARGETMANUID"));// 被访人员uid
			System.out.println("TARGETMANUID：-----------"+TARGETMANUID);
			if (TARGETMANUID != null && TARGETMANUID.equals("")) {
				String queryuser = "SELECT userid  FROM view_sastorginfo WHERE shortname='"+TARGETUNIT+"' and departmentname like  '%" + TARGETDEPT
						+ "%' AND username like  '%" + TARGETMAN + "%'";
				String userid = CoreUtil.objToStr(DBSql.getString(queryuser, "userid"));// 根据部门和姓名查询userid
				if (userid != null && !userid.equals("")) {
					DBSql.update("UPDATE BO_EU_VIT_MANGE_TOOFN SET TARGETMANUID = '" + userid + "' WHERE BINDID = '"
							+ processInstId + "'");

				} else {
					throw new BPMNError("查询不到被访部门的接待人员！");
				}
//			}
			


		}

		

		return true;
	}
}
